package com.example.springproject.xuwsh.mapper;

import com.example.springproject.xuwsh.domain.entry.UserEntry;
import com.example.xuwsh.myBatisPlus.core.query.JuXiLambdaQueryWrapper;
import com.example.xuwsh.myBatisPlus.core.update.JuXiLambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: xuwsh
 * @Date: 2023/09/20/16:38
 * @Description:
 */
@Service
public class UserMapperX {
    @Autowired
    private UserMapper userMapper;

    public List<UserEntry> selectByUserName(UserEntry userEntry) {
        JuXiLambdaQueryWrapper<UserEntry> queryWrapper = new JuXiLambdaQueryWrapper<>();
        queryWrapper.eqIfPresent(UserEntry::getUserName, userEntry.getUserName())
                    .eqIfPresent(UserEntry::getUserAge, userEntry.getUserAge())
                    .eqIfPresent(UserEntry::getOid, userEntry.getOid());
        return userMapper.selectList(queryWrapper);
    }

    public void updateUserName(UserEntry userEntry) {
        JuXiLambdaUpdateWrapper<UserEntry> wrapper = new JuXiLambdaUpdateWrapper<>();
        wrapper.eqIfPresent(UserEntry::getUserName, userEntry.getUserName()).setIfPresent(UserEntry::getUserAge, userEntry.getUserAge());
        userMapper.update(userEntry, wrapper);
    }

    public List<UserEntry> selectNeIfPresent(UserEntry userEntry) {
        JuXiLambdaQueryWrapper<UserEntry> queryWrapper = new JuXiLambdaQueryWrapper<>();
        queryWrapper.neIfPresent(UserEntry::getUserName, userEntry.getUserName());
        return userMapper.selectList(queryWrapper);
    }
}
